﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using thinger.MTHDLL;
using thinger.MTHModels;

namespace thinger.MTHProject
{
    public partial class FrmAdmin : Form
    {
        public FrmAdmin()
        {
            InitializeComponent();
            //设置焦点
            this.txtName.Focus();
        }

        private SysAdminManage sysAdminManage = new SysAdminManage();

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.txtName.Text.ToString().Trim() == null || this.txtName.Text.ToString().Trim().Length == 0)
            {
                new FrmMsgBoxWithOutAck("登录用户名不能为空", "请检查").Show();
            }
            if (this.txtPwd.Text.ToString().Trim() == null || this.txtPwd.Text.ToString().Trim().Length == 0)
            {
                new FrmMsgBoxWithOutAck("登录密码不能为空", "请检查").Show();
            }
            SysAdmin sysAdmin = new SysAdmin();

            sysAdmin.LoginName = this.txtName.Text.ToString().Trim();
            sysAdmin.LoginPwd = this.txtPwd.Text.ToString().Trim();

            try
            {
                SysAdmin sysAdmin1 = sysAdminManage.AdminLog(sysAdmin);

                if (sysAdmin1 == null)
                {
                    new FrmMsgBoxWithOutAck("登录失败", "请检查登录用户名和密码").Show();
                    return;
                }
                DialogResult dialogResult = new FrmMsgBoxWithAck("登录成功", "跳转到首页").ShowDialog();
                if (dialogResult == DialogResult.OK) 
                {
                    
                    CommonMethods.sysAdmin = sysAdmin1;

                    new FrmMain().Show();
                }
            }
            catch (Exception)
            {

                new FrmMsgBoxWithOutAck("登录失败", "请检查登录用户名和密码").Show();
            }
            

        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
